﻿<?php
if(!defined('IN_PHPSCUP'))exit('hacking'); 
class NewModel extends BaseModel
{

    var $table  = 'content';	

    var $_page_rows = 20;	
	
    /* 插入数据 */
    function insert_id()
    {    
	
	     $this->IU_Sql_Exe(array ('data' => array('table_id'=>"1",'is_show'=>"0"), 'mode' => 'INSERT'));
		 
		 return $this->db->insert_id();	 
        
    }

    /* 插入数据 */
    function select_id()
    {    
		 $info = $this->S_Sql_Exe(array('fields' =>'id','conditions' =>"user_id = '0' "));
    
		 return $info;
        
    }


    function delet_id()
    {    
		return $this->D_Sql_Exe(array ('conditions' =>"user_id = '0' "));
       
    }

	
    /* 插入数据 */
    function post($id,$data)
    {    
	
		$time = time();  
		
		$this->IU_Sql_Exe(array ('data' => array('cat_id'=>"$data[cat_id]",'user_id'=>"$data[user_id]",'user_name'=>"$data[user_name]",'table_id'=>"1",'keywords'=>"$data[keywords]",'description'=>"$data[description]",'add_time'=>"$time",'lastview'=>"$time",'is_show'=>"$data[yz]",'is_top'=>"$data[top]",'is_recommend'=>"$data[levels]",'is_index'=>"$data[special]",'config'=>"$data[config]",'lang_type'=>trim($GLOBALS['Lang']->_lang_tp)),'mode' => 'UPDATE','conditions' =>"id = '{$id}' "));   
    
		$this->IU_Sql_Exe(array ('table' => $this->_prefix . 'content_1','data' => array('con_id'=>"$id",'cat_id'=>"$data[cat_id]",'title'=>"$data[title]",'author'=>"$data[author]",'from_name'=>"$data[copyfrom]",'from_url'=>"$data[copyfromurl]",'content'=>"$data[content]",'picurl'=>"$data[picurl]"), 'mode' => 'INSERT'));

        
		
    }

    function show($order='',$v='',$word='')
    {  
	     empty($order)?$order = 'A.add_time desc':'';
		 
   	    $conditions = " A.user_id >0  and A.table_id=1 and lang_type='".trim($GLOBALS['Lang']->_lang_tp)."' ";
		 
		 foreach($word as $key => $value)
		 {

		     if($value)
		     {
		      $conditions .= " and C.title like '%{$value}%' ";
	  
		     }
		 }	
		  
/*	
  "SELECT A.*,C.* FROM content A LEFT JOIN content_1 C ON A.id=C.con_id WHERE A.id='$aid' ORDER BY R.rid ASC LIMIT 1"
	  
	  'table'=> $this->$table.'A LEFT JOIN '.$this->_prefix.'content_1  C ON A.id=C.con_id '
	  'fields'=> ' A.*,C.* ';
	  */
	  
	     $table = $this->table.' A LEFT JOIN '.$this->_prefix.'content_1'.' C ON A.id=C.con_id ';
	  
	      //分页时，一定是先调用page函数，再调用S_Sql_Exe函数
		 $info['page'] = $this->Page(array('table'=>"{$table}",'conditions' =>"{$conditions}",'url' => 'admin/?app=new&act=index&v='.$v));		
		 
		 $info['data'] = $this->S_Sql_Exe(array('table'=>"{$table}",'fields'=> ' A.*,C.* ','conditions' =>"{$conditions}",'order' =>"{$order}",'limit' =>$info['page']['sql_limit']));
    
		 return $info;
   
    }
	
	
    /* 删除数据 */
    function del($id ='')
    {      
		$this->D_Sql_Exe(array ('conditions' =>"id = '{$id}' "));
		$this->D_Sql_Exe(array ('table'=>"{$this->_prefix}content_1",'conditions' =>"con_id = '{$id}' "));		
        
    }

    /* 修改数据 */
    function editaction($id ='',$data = '')
    {    
		$time = time();  	      

		$this->IU_Sql_Exe(array ('data' => array('cat_id'=>"$data[cat_id]",'user_id'=>"$data[user_id]",'user_name'=>"$data[user_name]",'table_id'=>"1",'keywords'=>"$data[keywords]",'description'=>"$data[description]",'add_time'=>"$time",'lastview'=>"$time",'is_show'=>"$data[yz]",'is_top'=>"$data[top]",'is_recommend'=>"$data[levels]",'is_index'=>"$data[special]",'config'=>"$data[config]",'lang_type'=>trim($GLOBALS['Lang']->_lang_tp)),'mode' => 'UPDATE','conditions' =>"id = '{$id}' "));  
    
		$this->IU_Sql_Exe(array ('table' => $this->_prefix . 'content_1','data' => array('con_id'=>"$id",'cat_id'=>"$data[cat_id]",'title'=>"$data[title]",'author'=>"$data[author]",'from_name'=>"$data[copyfrom]",'from_url'=>"$data[copyfromurl]",'content'=>"$data[content]",'picurl'=>"$data[picurl]"), 'mode' => 'UPDATE','conditions' =>"con_id = '{$id}' "));
        
    }

    /* 修改数据 */
    function editpicurl($id ='',$data = '')
    {   
     
		return $this->IU_Sql_Exe(array ('table'=>"{$this->_prefix}content_1",'data' => array('picurl'=>"$data[picurl]"),'mode' => 'UPDATE','conditions' =>"con_id = '{$id}' "));
        
    }


    /* 修改数据 */
    function editname($id ='',$data = '')
    {   
     
		return $this->IU_Sql_Exe(array ('data' => array('name'=>"$data[name]"),'mode' => 'UPDATE','conditions' =>"id = '{$id}' "));
        
    }


    /* 修改数据 */
    function editstatus($id ='',$data = '')
    {   
     
		return $this->IU_Sql_Exe(array ('data' => array('status'=>"$data[status]"),'mode' => 'UPDATE','conditions' =>"id = '{$id}' "));
        
    }



    /* 通过id取出一条数据 */
    function oneshow($id ='')
    {    
	    

	     $table = $this->table.' A LEFT JOIN '.$this->_prefix.'content_1'.' C ON A.id=C.con_id ';
	  
		 $info = $this->S_Sql_Exe(array('table'=>"{$table}",'fields'=> ' A.*,C.* ','conditions' =>"A.id='{$id}' and A.user_id >0 ",'return' =>'one'));
    
		 return $info;
        
    }


}




?>